package com.zhiwang.planet.ui.jsmodule

import android.webkit.JavascriptInterface
import com.planet.processor.JsModule
import com.scwang.smartrefresh.layout.SmartRefreshLayout
import com.zhiwang.planet.ui.BaseActivity

@JsModule
class RefreshJsModule constructor(
        context: BaseActivity,
        val refresh: SmartRefreshLayout,
        val refreshAction: () -> Unit)
    : BaseJsModule(context) {


    @JavascriptInterface
    fun refresh() {
        context.runOnUiThread {
            refresh.autoRefresh()
            refreshAction.invoke()
        }

    }

    @JavascriptInterface
    fun setRefreshEnabled(enable: String) {
        when (enable) {
            "true" -> refresh.setEnableRefresh(true)
            "false" -> refresh.setEnableRefresh(false)
        }
    }
}